package UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Server {
    public static void main(String[] args) throws Exception {
        //1、创建一个端口号
        DatagramSocket socket=new DatagramSocket(8899);
        //接收包
        byte [] bus=new byte[1024];
        DatagramPacket packet=new DatagramPacket(bus,0,bus.length);
        //堵塞接收
        socket.receive(packet);
        //输出数据
        System.out.println(packet.getAddress().getHostAddress());
        System.out.println(new String(packet.getData(),0, packet.getLength()));
        //关闭连接
        socket.close();
    }
}
